/*
 * Copyright (c) 2025 Huawei Device, Inc. Ltd. and <马弓手>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MYAPPLICATION_HTTPURL_H
#define MYAPPLICATION_HTTPURL_H

#include <map>
#include <string>
using namespace std;

/**
 * @brief url处理相关函数
 */
class HttpUrl {
     static const unsigned int LOG_PRINT_DOMAIN = 0xFF00;
     static map<std::string, std::string> s_mapMimeType;
public:
    /**
     * @brief Gets mime
     * @param strFilePath url path
     * @return mime
     */
    static string GetMimeType(const string& strFilePath);
    /**
     * @brief Gets mime
     * @param resourceType 
     * @param strUrlPath
     * @return mime
     */
    static string GetMimeType(const int resourceType, const string& strUrlPath);
    /**
     * @brief Removes leading and trailing whitespace, including '\r' and '\n'.
     * @param strValue Input string.
     * @return Trimmed string.
     */
    static string trim(const string & strValue);
    /**
     * @brief Splits a string.
     * @param strString Input string.
     * @param split split Delimiter.
     * @param vecString Output vector of split strings.
     */
    static void SplitString(const string& strString, const string & split, vector<string>& vecString);
    /**
     * @brief Generates an MD5 hash.
     * @param strIn Input string.
     * @return MD5 hash value.
     */
    static string generateMD5(const string& strIn);
    
    /**
     * Determine the end of the string
     * @param str
     * @param suffix
     * @return
     */
    static bool endsWithEqual(const string& str, const string& suffix);
    
    /**
     * @brief Removes duplicate items from a vector.
     * @tparam T Data type.
     * @param vecData Input vector.
     */
    template<class T>
    static void DiffContData(vector<T>& vecData) {
    typedef typename vector<T>::iterator _IT;
            _IT it, currIt;
        int nSize = vecData.size();
        int nPos = 0;
        for(int i=0, nPos=0; nPos<nSize;) {
            T tValue = vecData[i];
            currIt = vecData.begin()+i;
            it = find(vecData.begin()+i+1, vecData.end(), tValue);
            if(it != vecData.end())
                vecData.erase(currIt);
            else
                i++;
            nPos++;
         }
         return;
    }
    
    /**
     * @brief 转小写
     * @param str
     * @return
     */
    static string toLower(const string & str);
};

#endif //MYAPPLICATION_HTTPURL_H
